﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class PR_SalaryPromote : System.Web.UI.Page
    {
        private SsMng ssMng = new SsMng();
        //Command_BLL salaryCommandBLL = new Command_BLL();
        private IEmployeeTypeBLL empTypeBLL = new EmployeeTypeBLL();
        private ICommandBLL cmdBLL = new CommandBLL();
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindEmpType();
                //LoadDataGrid();
            }
            
        }
        
        private void LoadDataGrid()
        {
            Nullable<int> nEmpTypeSeq = ddlEmployeeType.SelectedValue.Length > 0 ? Int32.Parse(ddlEmployeeType.SelectedValue) : (int?)null;
            try
            {
                IList<CommandInfo> infoList = cmdBLL.ListCommand(SystemInfo._CmdEmployee, (int?)null, 1001, nEmpTypeSeq);
                RadGrid2.DataSource = infoList;// ListSalaryCommand.Tables[0];
                GridGroupByExpression g = new GridGroupByExpression(RadGrid2.Columns[7]);
                RadGrid2.MasterTableView.GroupByExpressions.Add(g);
                RadGrid2.DataBind();
            }
            catch (Exception ex)
            {

            }
        }
        private void bindEmpType()
        {
            try
            {
                IList<EmployeeTypeInfo> infoList = empTypeBLL.ListEmployeeTypes();
                ddlEmployeeType.DataSource = infoList;
                ddlEmployeeType.DataBind();
            }
            catch
            {

            }
        }
        protected void RadGrid2_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                int seq = Convert.ToInt32((e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Sequence"]);
                cmdBLL.Delete(SystemInfo._CmdEmployee, seq, ssMng.EmpSeqI);
            }
            if (e.CommandName == "ExpandCollapse")
                return;

            Session["CMDTYPE"] = "1001";
            LoadDataGrid();
        }

        protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
        {
            //if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
            //{
            //    string scr;
            //    if (e.Item.Cells[9].Text == "1")
            //        scr = "<img src='../Images/Buttons/Update.gif'>";
            //    else
            //        scr = "<img src='../Images/Buttons/Cancel.gif'>";
            //    e.Item.Cells[9].Text = scr;
            //}
        }

        protected void ddlEmployeeType_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            Session["EMPTYPE"] = ddlEmployeeType.SelectedValue;
            LoadDataGrid();
        }
    }
}
